import router from "@src/router";
import { OPEN_STATE_TEXT } from "@src/sp-reservation/constant/index.js";
import { resolveTimeAddZero } from "@src/common/reservation/config/index.js";

Component({
  options: {
    addGlobalClass: true,
    isHiddenTips: true,
  },
  properties: {
    imageList: {
      type: Array,
      value: [],
    },
    shopInfo: {
      type: Object,
      value: {},
    },
    isScrollToTop: {
      type: Boolean,
      value: true,
    },
  },

  data: { OPEN_STATE_TEXT, indicatorIndex: 1 },
  methods: {
    resolveTimeAddZero,
    handleToShopDetail(e) {
      // const {
      //   currentTarget: {
      //     dataset: {
      //       value: { value },
      //     },
      //   },
      // } = e;
      router.push({
        name: "reservation/detail",
        params: {
          shopId: this.data.shopInfo.shopId,
          // navIndex: e.currentTarget.dataset.index,
        },
      });
    },
    handleImageChange(e) {
      let indicatorIndex = e.detail.current + 1;
      this.setData({ indicatorIndex: indicatorIndex });
    },
    handleToShopList() {
      router.push({
        name: "reservation/shopList",
        events: {
          changeShop: (shopId) => {
            if (shopId !== this.data.shopId) {
              this.triggerEvent("changeShop", { shopId: shopId });
            }
          },
        },
      });
    },
    handleToMap() {
      const latitude = this.data.shopInfo.latitude;
      const longitude = this.data.shopInfo.longitude;
      const name = this.data.shopInfo.name;
      const address = this.data.shopInfo.address;
      wx.openLocation({ latitude, longitude, name, address, scale: 18 });
    },
    handleShowText() {
      this.setData({
        isHiddenTips: !this.data.isHiddenTips,
      });
    },
  },
});
